public class test {

}
 class Counter {
    private int count = 0;

    // 同步方法确保线程安全
    public synchronized void increment() {
        count++;
    }

    public int getCount() {
        return count;
    }
}
